Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location conversion tests for relay and parachains #487

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

x3c41a
Copy link

@x3c41a x3c41a commented Oct 17, 2024

Added location convertion tests.
Polkadot sdk PR
Fixes #488

@x3c41a x3c41a marked this pull request as draft October 17, 2024 17:03
@x3c41a x3c41a marked this pull request as ready for review October 17, 2024 20:36
@x3c41a x3c41a marked this pull request as draft October 17, 2024 20:36
@x3c41a x3c41a changed the title Loc conv test Location conversion tests for relay and parachains Oct 18, 2024
@x3c41a x3c41a marked this pull request as ready for review October 18, 2024 09:47
Copy link
Contributor

@acatangiu acatangiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversions are the same for all system parachains, so this test could be a macro to dedup the code, but I don't know where we would put that macro or if it's worth the effort. I'm fine with the duplicated code too.

Please see the other comments.

Comment on lines 35 to 118
// DescribeTerminus
TestCase {
description: "DescribeTerminus Parent",
location: Location::new(1, Here),
expected_account_id_str: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD",
},
TestCase {
description: "DescribeTerminus Sibling",
location: Location::new(1, [Parachain(1111)]),
expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk",
},
// DescribePalletTerminal
TestCase {
description: "DescribePalletTerminal Parent",
location: Location::new(1, [PalletInstance(50)]),
expected_account_id_str: "5CnwemvaAXkWFVwibiCvf2EjqwiqBi29S5cLLydZLEaEw6jZ",
},
TestCase {
description: "DescribePalletTerminal Sibling",
location: Location::new(1, [Parachain(1111), PalletInstance(50)]),
expected_account_id_str: "5GFBgPjpEQPdaxEnFirUoa51u5erVx84twYxJVuBRAT2UP2g",
},
// DescribeAccountId32Terminal
TestCase {
description: "DescribeAccountId32Terminal Parent",
location: Location::new(
1,
[AccountId32 { network: None, id: AccountId::from(ALICE).into() }],
),
expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4",
},
TestCase {
description: "DescribeAccountId32Terminal Sibling",
location: Location::new(
1,
[
Parachain(1111),
Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() },
],
),
expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg",
},
// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg",
},
TestCase {
description: "DescribeAccountKey20Terminal Sibling",
location: Location::new(
1,
[Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }],
),
expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg",
},
// DescribeTreasuryVoiceTerminal
TestCase {
description: "DescribeTreasuryVoiceTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]),
expected_account_id_str: "5CUjnE2vgcUCuhxPwFoQ5r7p1DkhujgvMNDHaF2bLqRp4D5F",
},
TestCase {
description: "DescribeTreasuryVoiceTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }],
),
expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB",
},
// DescribeBodyTerminal
TestCase {
description: "DescribeBodyTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Unit, part: BodyPart::Voice }]),
expected_account_id_str: "5EBRMTBkDisEXsaN283SRbzx9Xf2PXwUxxFCJohSGo4jYe6B",
},
TestCase {
description: "DescribeBodyTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }],
),
expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parent and Sibling (parachain) locations do not make sense for a Relay chain.

All of these should be replaced with Child (parachain) locations.
(DescribeTerminus Child, DescribePalletTerminal Child, etc)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 35 to 118
// DescribeTerminus
TestCase {
description: "DescribeTerminus Parent",
location: Location::new(1, Here),
expected_account_id_str: "5GyWtDJP7qaipWRGr4KJ6VUDxRXf4jDnPW6KPTeCekHfqZkD",
},
TestCase {
description: "DescribeTerminus Sibling",
location: Location::new(1, [Parachain(1111)]),
expected_account_id_str: "5EC5GfEFm9XEBYjXzxb1VseMHsG2VhPeGTGWF9H8tYZnGsSk",
},
// DescribePalletTerminal
TestCase {
description: "DescribePalletTerminal Parent",
location: Location::new(1, [PalletInstance(50)]),
expected_account_id_str: "5CnwemvaAXkWFVwibiCvf2EjqwiqBi29S5cLLydZLEaEw6jZ",
},
TestCase {
description: "DescribePalletTerminal Sibling",
location: Location::new(1, [Parachain(1111), PalletInstance(50)]),
expected_account_id_str: "5GFBgPjpEQPdaxEnFirUoa51u5erVx84twYxJVuBRAT2UP2g",
},
// DescribeAccountId32Terminal
TestCase {
description: "DescribeAccountId32Terminal Parent",
location: Location::new(
1,
[AccountId32 { network: None, id: AccountId::from(ALICE).into() }],
),
expected_account_id_str: "5DN5SGsuUG7PAqFL47J9meViwdnk9AdeSWKFkcHC45hEzVz4",
},
TestCase {
description: "DescribeAccountId32Terminal Sibling",
location: Location::new(
1,
[
Parachain(1111),
Junction::AccountId32 { network: None, id: AccountId::from(ALICE).into() },
],
),
expected_account_id_str: "5DGRXLYwWGce7wvm14vX1Ms4Vf118FSWQbJkyQigY2pfm6bg",
},
// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
expected_account_id_str: "5F5Ec11567pa919wJkX6VHtv2ZXS5W698YCW35EdEbrg14cg",
},
TestCase {
description: "DescribeAccountKey20Terminal Sibling",
location: Location::new(
1,
[Parachain(1111), AccountKey20 { network: None, key: [0u8; 20] }],
),
expected_account_id_str: "5CB2FbUds2qvcJNhDiTbRZwiS3trAy6ydFGMSVutmYijpPAg",
},
// DescribeTreasuryVoiceTerminal
TestCase {
description: "DescribeTreasuryVoiceTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]),
expected_account_id_str: "5CUjnE2vgcUCuhxPwFoQ5r7p1DkhujgvMNDHaF2bLqRp4D5F",
},
TestCase {
description: "DescribeTreasuryVoiceTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }],
),
expected_account_id_str: "5G6TDwaVgbWmhqRUKjBhRRnH4ry9L9cjRymUEmiRsLbSE4gB",
},
// DescribeBodyTerminal
TestCase {
description: "DescribeBodyTerminal Parent",
location: Location::new(1, [Plurality { id: BodyId::Unit, part: BodyPart::Voice }]),
expected_account_id_str: "5EBRMTBkDisEXsaN283SRbzx9Xf2PXwUxxFCJohSGo4jYe6B",
},
TestCase {
description: "DescribeBodyTerminal Sibling",
location: Location::new(
1,
[Parachain(1111), Plurality { id: BodyId::Unit, part: BodyPart::Voice }],
),
expected_account_id_str: "5DBoExvojy8tYnHgLL97phNH975CyT45PWTZEeGoBZfAyRMH",
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parent and Sibling (parachain) locations do not make sense for a Relay chain.

All of these should be replaced with Child (parachain) locations.
(DescribeTerminus Child, DescribePalletTerminal Child, etc)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 749 to 752
[AccountId32 {
network: None,
id: polkadot_core_primitives::AccountId::from(ALICE).into(),
}],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can dedup at least these "Alice" AccountIds used throughout the test:

Suggested change
[AccountId32 {
network: None,
id: polkadot_core_primitives::AccountId::from(ALICE).into(),
}],
[alice.clone()],

and have at the beginning of the test a

let alice = AccountId32 {
	network: None,
	id: polkadot_core_primitives::AccountId::from(ALICE).into(),
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

// DescribeAccountKey20Terminal
TestCase {
description: "DescribeAccountKey20Terminal Parent",
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these AccountKey20s:

Suggested change
location: Location::new(1, [AccountKey20 { network: None, key: [0u8; 20] }]),
location: Location::new(1, [bob_20.clone()]),

with

let bob_20 = AccountKey20 { network: None, key: [123u8; 20] }

(notice I also suggested using non-zero keys)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☑️
Out of curiosity, what edge-case you want to avoid by eliminating zero keys?

@x3c41a
Copy link
Author

x3c41a commented Oct 23, 2024

bot fmt

@x3c41a
Copy link
Author

x3c41a commented Oct 23, 2024

The conversions are the same for all system parachains, so this test could be a macro to dedup the code, but I don't know where we would put that macro or if it's worth the effort. I'm fine with the duplicated code too.

Please see the other comments.

I don't feel like writing macros just yet, still want to get used to Rust.

@x3c41a x3c41a requested a review from acatangiu October 23, 2024 11:11
@x3c41a x3c41a marked this pull request as draft October 23, 2024 11:37
@x3c41a x3c41a marked this pull request as ready for review October 23, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate foreign locations to local accounts converter when upgrading polkadot-sdk to a newer version
3 participants